package net.tycmc.cty.ctyms.timejob.iems.service;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.Main;

import net.sf.json.JSONObject;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.cty.ctyms.timejob.common.DateControl;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;
import net.tycmc.cty.ctyms.timejob.common.DynamicReadConfig;
import net.tycmc.cty.ctyms.timejob.common.EquipVersionCommon;
import net.tycmc.cty.ctyms.timejob.common.ListUtil;
import net.tycmc.cty.ctyms.timejob.common.NumberFormat;
import net.tycmc.cty.ctyms.timejob.iems.dao.DrivingBehavior2DAO;

/**
 * 对比分析数据统计作业
 * @author fujichuan
 *
 */
public class DrivingBehavior2Service {
	public  Logger logdb2=Logger.getLogger("DB2Vcl");
	public  Logger logdb2yanchi=Logger.getLogger("DB2VclYanchi");
	private DrivingBehavior2DAO drivingBehavior2DAO;
	public DrivingBehavior2DAO getDrivingBehavior2DAO() {
		return drivingBehavior2DAO;
	}

	public void setDrivingBehavior2DAO(DrivingBehavior2DAO drivingBehavior2DAO) {
		this.drivingBehavior2DAO = drivingBehavior2DAO;
	}
	
	// 颜色key集合
	String[] colKeyArr = { "ParaSDD2_Col10", "ParaSDD2_Col20",
				"ParaSDD2_Col30", "ParaSDD2_Col40", "ParaSDD2_Col45",
				"ParaSDD2_Col50", "ParaSDD2_Col55", "ParaSDD2_Col60",
				"ParaSDD2_Col65", "ParaSDD2_Col70", "ParaSDD2_Col75",
				"ParaSDD2_Col80", "ParaSDD2_Col85", "ParaSDD2_Col90",
				"ParaSDD2_Col95", "ParaSDD2_Col100", "ParaSDD2_Colgt100",
				"ParaSDD2_ColTotal" };
	// 值key集合
	String[] valKeyArr = { "ParaSDD2_Val10", "ParaSDD2_Val20",
				"ParaSDD2_Val30", "ParaSDD2_Val40", "ParaSDD2_Val45",
				"ParaSDD2_Val50", "ParaSDD2_Val55", "ParaSDD2_Val60",
				"ParaSDD2_Val65", "ParaSDD2_Val70", "ParaSDD2_Val75",
				"ParaSDD2_Val80", "ParaSDD2_Val85", "ParaSDD2_Val90",
				"ParaSDD2_Val95", "ParaSDD2_Val100", "ParaSDD2_Valgt100",
				"ParaSDD2_ValTotal" };
	
	/**
	 * 统计执行档位及车速
	 * @throws IOException 
	 */
	public void execStart(String Db2Time,String vehicleID) {
		//查看配置文件是否需要将数据进行备份1：备份，0：不备份
		String isbakTable="";
		String time[]=new String[2];
		String start = DateControl.getDateTime(0);
		logdb2.info("-----车辆档位及车速统计作业开始------开始时间："+start);
		try {
			isbakTable = DynamicReadConfig.getConfigProperty("config.properties", "DrivingBehavior2");
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(!StringUtil.isValid(isbakTable)){
			isbakTable = "0";
		}
		if(StringUtil.isValid(Db2Time)){
			time=Db2Time.split("~");
		}else{
			time=new String[]{DateUtil.addDay(-1),DateUtil.addDay(-1)};
		}
		List<String>list=DateRegUtil.iterateTime(time[0], time[1]);
		for(int i=list.size()-1;i>=0;i--){
			//这次统计时间
			String thisWorkDay =list.get(i);
			//这次统计的设备
			String vclId="";
			//统计昨天的数据
			startExecu(thisWorkDay,vclId,logdb2,isbakTable);
		}
			
		//延迟数据处理
		logdb2.info("-----车辆档位及车速统计作业结束------执行时间："+DateControl.getMiaoShu(start,DateControl.getDateTime(0)));
	}
	/**
	 * 统计执行档位及车速延迟数据
	 * @throws IOException 
	 */
	public void execDeloyStart()  {
		logdb2yanchi.info("数据统计作业-统计档位和车速延迟数据开始："+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd HH:mm:ss")+"~");
		System.out.println("数据统计作业-统计档位和车速延迟数据开始："+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd HH:mm:ss")+"~");
		//查看配置文件是否需要将数据进行备份1：备份，0：不备份
		String isbakTable = "";
		try {
			isbakTable = DynamicReadConfig.getConfigProperty("config.properties", "DrivingBehavior2");
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(!StringUtil.isValid(isbakTable)){
			isbakTable = "0";
		}
		//查询档位及车速延迟数据
		List<Map<String,Object>>resultlist=this.drivingBehavior2DAO.getDelayDataOfGrASp();
		String MaxId="0";
		if(resultlist.size()>0){
			MaxId=MapGetter.getString(resultlist.get(resultlist.size()-1),"Msgid");
			System.out.println("本次延迟表中最大id为-----------------"+MaxId);
		}
		int num=0;
		if(null!=resultlist&&resultlist.size()>0){
			num=resultlist.size();
			//将结果按时间分组，按天统计延迟数据
			Map<String,List<Map<String,Object>>> mapresult=new ListUtil().groupBy("MsgTime", resultlist);
			Set<String>set=mapresult.keySet();
			for(Iterator<String> it=set.iterator();it.hasNext();){
				//k:日期    将设备id拼成字符串12,23,3的形式
				//获取Map的Key 例如”2015-06-30“
				String k=it.next();
				//获取此时间下返回延迟数据的所有设备集合
				List<Map<String,Object>>list=mapresult.get(k);
				//拼接设备id
				int numchu=list.size()/50;
				int numyu=list.size()%50;
				for(int i=0;i<=numchu;i++){       
					List<Map<String,Object>>listsub=new ArrayList<Map<String,Object>>();
					String vclString="";
					if(i==numchu){
						listsub=list.subList(i*50,i*50+numyu);
					}else{
						listsub=list.subList(i*50,i*50+50);
					}
					for(Map<String,Object>map:listsub){
						vclString=vclString+","+MapGetter.getString(map,"Vclid");
					}
					if(vclString.length()>0){
						vclString=vclString.substring(1,vclString.length());
						//执行这些设备的统计
						startExecu(k,vclString,logdb2yanchi,isbakTable);
					}
				}
				
			}
			if(!"0".equals(MaxId)){
			drivingBehavior2DAO.updateMaxId(MaxId);
			
			}
		}
		logdb2yanchi.info("数据统计作业-统计档位和车速延迟数据结束："+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd HH:mm:ss")+"~~~~此次需重新统计统计"+num+"条");
		System.out.println("数据统计作业-统计档位和车速延迟数据结束："+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd HH:mm:ss")+"~~~~此次需重新统计统计"+num+"条");	

	}
	public void startExecu(String thisWorkDay,String vclId,Logger log,String isbakTable) {
		System.out.println("本次统计日期-------"+thisWorkDay+",统计设备id-------"+vclId);
		boolean isExit = drivingBehavior2DAO.checkCreateRoadInfo(thisWorkDay.substring(0, 7).replace("-", ""),isbakTable);
		System.out.println("isExit------------"+isExit);
		if(!isExit){
			System.out.println("车辆档位及车速统计表不存在"+thisWorkDay);
		}
		//sql语句集合列表
		List<String> sqlList = new ArrayList<String>();
		//统计档位和车速部分数据
		String DBVcl_JPP2 = EquipVersionCommon.getSoftVerByAgrType("DBVcl_JPP2").toLowerCase();
		//统计档位和车速部分数据(432协议)
		String DBVcl_JPP2_432 = EquipVersionCommon.getSoftVerByAgrType("AccelerationUse").toLowerCase();
		//湘邮一期502协议
		String DBVcl_JPP2_502 = EquipVersionCommon.getSoftVerByAgrType("DBVcl_JPP2_502").toLowerCase();
		//统计驾驶行为2各设备各档位数据信息
		String[] dbTypelist = drivingBehavior2DAO.getDBType();
		List<Map<String, Object>> cnMapList = this.getDriver2SubPer(DBVcl_JPP2,DBVcl_JPP2_432,DBVcl_JPP2_502,thisWorkDay,dbTypelist,sqlList,vclId,isbakTable);
		
		//所统计设备数据处理
		//获取颜色配置信息
		Map<String,List<Map<String, Object>>> paraSetListMap = this.paraSetList(cnMapList,thisWorkDay,vclId);
		List<Map<String,Object>> colorList = this.drivingBehavior2DAO.getColorSetList();
		Map<String,Map<String,Object>> param = new HashMap<String,Map<String,Object>>();
		String tmnlof432 =EquipVersionCommon.getSoftVerByAgrType("AccelerationUse").toLowerCase();
		for (Map<String,Object>	map : colorList) {
			param.put(MapGetter.getString(map, "CS_Code"), map);
		}
		List<Map<String, Object>> paraSetList = new ArrayList<Map<String,Object>>();
		//循环
		//删除之前统计的本次数据
		StringBuffer sbSQL = new StringBuffer();
		sbSQL.append("delete from VclDB2_"+thisWorkDay.substring(0, 7).replace("-", "")+" where vcldb2_statetime='"+thisWorkDay+"' ");
		if(StringUtil.isValid(vclId)){
			sbSQL.append(" and vcldb2_vcl_id in ("+vclId+"); ");
			sqlList.add(sbSQL.toString());
		} else {
			sbSQL.append("; ");
		}
		
		String vehicleid = "";
		for (Map.Entry<String, List<Map<String, Object>>> entry : paraSetListMap.entrySet()) {
			paraSetList = entry.getValue();
			vehicleid = entry.getKey();
			String dutyData  = "";
			String flag="false";
			String flag1="false";
			Map<String, Object> data = this.colorJS(paraSetList.size(), paraSetList, param);
			//查询此车是否配置了 执行带档滑行
			boolean isSetDH = this.drivingBehavior2DAO.isSetDH(vehicleid);
			String Vcltmnl="'"+MapGetter.getString(data,"tmnl")+"'";
			if(tmnlof432.toLowerCase().contains(Vcltmnl.toLowerCase())){
				flag="true";
			}
			if(DBVcl_JPP2_502.toLowerCase().contains(Vcltmnl.toLowerCase())){
				flag1="true";
			}
			if(isSetDH){
			//获取设备工作循环数据（按时间段）
			 dutyData = this.getDutyCycleDataOfBetweenTime(vehicleid,DateUtil.addDay(thisWorkDay, -1),thisWorkDay,"",flag);	
			}
			this.drivingBehavior2DAO.driverTwoSql(thisWorkDay,data,param,vehicleid,dbTypelist,dutyData,sqlList,flag,flag1);
		}

		try {
			log.info(sqlList.toString());
			this.drivingBehavior2DAO.executeSql(sqlList,isbakTable);
		
		} catch (Exception e) {
			System.out.println("统计档位和车速部分数据出现异常："+e);
		}
		System.out.println("数据统计作业-统计档位和车速部分数据结束："+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd HH:mm:ss")+"~");
		sqlList.clear();
		
		
	
	}
	
	/**
	 * 驾驶行为分析2数据
	 * 
	 * @param paraSetList
	 * @return
	 */
	public Map<String,List<Map<String, Object>>> paraSetList(List<Map<String, Object>> cnMapList,String thisWorkDay,String vclId) {
		//档位及车速各个设备设置信息
		List<Map<String, Object>> paraSetList = drivingBehavior2DAO.getVclParaSetInfo(thisWorkDay,vclId);
		// 每个设备对应的List列表
		List<Map<String, Object>> listSet = new ArrayList<Map<String, Object>>();
		// 每个设备对应的List列表
		List<Map<String, Object>> listCn = new ArrayList<Map<String, Object>>();
		// 按照指定key，将listMap封装成 MAP<设备ID，List<Map<String,Object>>>
		Map<String, List<Map<String, Object>>> cnMap = new ListUtil().groupBy("vehicleID", cnMapList);
		
		Map<String, Object> totalGearMap = new HashMap<String, Object>();
		// 按照指定key，将listMap封装成 MAP<设备ID，List<Map<String,Object>>>
		Map<String, List<Map<String, Object>>> paraSetMap = new ListUtil().groupBy("ParaSD2_Vcl_ID", paraSetList);
		
		//循环
		String vehicleid = "";
		for (Map.Entry<String, List<Map<String, Object>>> entry : paraSetMap.entrySet()) {
			listSet = entry.getValue();
			
			vehicleid = entry.getKey();
			
			listCn = cnMap.get(vehicleid);
			Map<String, Object> map = new HashMap<String, Object>();
			if(listCn!=null && listCn.size()>0){
				map = listCn.get(0);
			}
			String key = "";// 获取数据值的Key
			double valTotal = 0;// 页面总合计
			for (int j = listSet.size() - 1; j >= 0; j--) {
				Map<String, Object> SetMap = listSet.get(j);
				//此设备所有档位发生次数和
				SetMap.put("ZG1S",MapGetter.getString(map,"total0G1S"));
				SetMap.put("totalCnt", MapGetter.getString(map,"totalCnt"));
				SetMap.put("ZG3S", MapGetter.getString(map,"total0G3S"));
				SetMap.put("tmnl", MapGetter.getString(map,"tmnl"));
				SetMap.put("DDHXNums", MapGetter.getString(map,"DDHXNums"));
				double valTotalGear = 0;// 每个档位的合计
				for (int i = 0; i < valKeyArr.length; i++) {
					if (j == 0) {
						SetMap.put(valKeyArr[i], MapGetter.getString(totalGearMap, valKeyArr[i]));
					} else {
						key = MapGetter.getString(SetMap, "ParaSDD2_Grear")+ "G";
						key += (i + 1) + "S";
						double valGear = 0;
						if (StringUtil.isNullOrEmpty(MapGetter.getString(map,key))) {
							valGear = Double.parseDouble(MapGetter.getString(map, key));
						}
						valTotalGear = NumberFormat.add(valTotalGear, valGear);
						SetMap.put(valKeyArr[i], valGear);
						if (!StringUtil.isNullOrEmpty(MapGetter.getString(totalGearMap, valKeyArr[i]))) {
							totalGearMap.put(valKeyArr[i], valGear);
						} else {
							totalGearMap.put(valKeyArr[i], NumberFormat.add(Double.parseDouble(MapGetter.getString(totalGearMap,valKeyArr[i])), valGear));
						}
					}
				}
				if (j == 0) {
					SetMap.put("ParaSDD2_ValTotal", valTotal);
				} else {
					SetMap.put("ParaSDD2_ValTotal", valTotalGear);
				}
				valTotal = NumberFormat.add(valTotal, valTotalGear);
			}
		}
		
		return paraSetMap;
	}
	
	/**
	 * 查询范围内容行为档位、速度次数百分比
	 * @param soft
	 * @param thisWorkDay
	 * @return
	 */
	public List<Map<String, Object>> getDriver2SubPer(String soft,String soft432,String soft502,String thisWorkDay,String[] dbTypelist,List<String> sqlList,String vclId,String isbakTable){
		
		/**-----------------------档位及车速各档位及速度发生总次数------------------------**/
		List<Map<String,Object>> totalCntList = drivingBehavior2DAO.getDriver2TotalCount(soft, thisWorkDay,vclId);
		List<Map<String,Object>> totalCntList432 = drivingBehavior2DAO.getDriver2TotalCount432(soft432, thisWorkDay,vclId);
		List<Map<String,Object>> totalCntList502 = drivingBehavior2DAO.getDriver2TotalCount502(soft502, thisWorkDay,vclId);
		totalCntList.addAll(totalCntList432);
		totalCntList.addAll(totalCntList502);
		Map<String, Object> totalCntMap = new HashMap<String, Object>();
		int totalCnt = 0;
		for(Map<String,Object> mapTol : totalCntList){
			/*if("0".equals(MapGetter.getString(mapTol, "totalCnt"))){
				//总次数为0的先处理
				sqlList.add(drivingBehavior2DAO.insertZero(thisWorkDay,MapGetter.getString(mapTol, "vehicleid"),dbTypelist));
				continue;
			}*/
			totalCntMap.put(MapGetter.getString(mapTol, "msgdb2_vcl_id"), MapGetter.getString(mapTol, "totalCnt"));
		}
		try {
			if(null != sqlList && sqlList.size()>0){
				this.drivingBehavior2DAO.executeSql(sqlList,isbakTable);
				sqlList.clear();
			}
		} catch (Exception e) {
			System.out.println("统计档位和车速部分数据出现异常："+e);
		}
		/**-----------------------档位及车速各档位及速度发生总次数------------------------**/
		
		/**-----------------------档位及车速各档位及速度分别发生次数------------------------**/
		List<Map<String, Object>> valCntList = drivingBehavior2DAO.getDriver2SubCount(soft, thisWorkDay,vclId);
		List<Map<String, Object>> valCntList432 = drivingBehavior2DAO.getDriver2SubCount432(soft432, thisWorkDay,vclId);
		List<Map<String, Object>> valCntList502 = drivingBehavior2DAO.getDriver2SubCount502(soft502, thisWorkDay,vclId);
		valCntList.addAll(valCntList432);
		valCntList.addAll(valCntList502);
		// 每个设备对应的List列表
		List<Map<String, Object>> valList = new ArrayList<Map<String, Object>>();
		// 按照指定key，将listMap封装成 MAP<设备ID，List<Map<String,Object>>>
		Map<String, List<Map<String, Object>>> valCntListMap = new ListUtil().groupBy("msgdb2_vcl_id", valCntList);
		/**-----------------------档位及车速各档位及速度分别发生次数------------------------**/
		Map<String,Object>params=new HashMap<String, Object>();//求怠速及工作时长 参数集合
		Map<String,Object>paramTen=new HashMap<String, Object>();//保存OG1S的次数，为了后面与怠速做差
		params.put("s_time",thisWorkDay+" 00:00:00");
		params.put("e_time",thisWorkDay+" 23:59:59");
		String vehicleID = "";
		//返回结果
		List<Map<String, Object>> listDataMap = new ArrayList<Map<String, Object>>();
		// 循环,取每个设备对应的LIST在循环
		String tmnl_softedition="";
		String DDHXNums="";
		int DDnum = 0;
		String tmnlof432 = "";
		try {
			tmnlof432 = DynamicReadConfig.getConfigProperty("softveragreement.properties", "AccelerationUse").toLowerCase();
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (Map.Entry<String, List<Map<String, Object>>> entry : valCntListMap.entrySet()) {
			Map<String,Object> retMap = new HashMap<String,Object>();
			vehicleID = entry.getKey();
			if(!StringUtil.isNull(MapGetter.getString(totalCntMap, vehicleID)))continue;
			valList = entry.getValue();
			
			//此设备ID发生的总次数
			totalCnt = StringUtil.isValid(MapGetter.getString(totalCntMap, vehicleID))?Integer.parseInt(MapGetter.getString(totalCntMap, vehicleID)):0;
			if(totalCnt>0){
				//各档位各车速列表
				Map<String,Object> MapGS = new HashMap<String,Object>();
				String key = "";
				int value = 0;
				String jsonStr = "";
				if(null!=valList&&valList.size()>0){
					tmnl_softedition=MapGetter.getString(valList.get(0),"tmnl_softedition");
					DDHXNums = MapGetter.getString(valList.get(0),"MsgDB2_SlidingTime");
				}
				for(Map<String,Object> map:valList){
					jsonStr = MapGetter.getString(map, "subcnt");
					if(StringUtil.isValid(jsonStr)){
						JSONObject joPa = JSONObject.fromObject(jsonStr);					
						Iterator<String>  it=joPa.keys();
						while(it.hasNext()){
							//档位车速（XX_XX）
							String keyGS=it.next();
							//次数
							Object valueGS=joPa.get(keyGS);
							if(!StringUtil.isValid(valueGS)){
								valueGS = 0;
							}
							//相同的KEY值加起来求和为次档位此速度总次数，单台设备查询，不用考虑设备号
							if(MapGS.containsKey(keyGS)){
								MapGS.put(keyGS, Integer.parseInt(valueGS.toString())+Integer.parseInt(MapGS.get(keyGS).toString()));
							} else {
								MapGS.put(keyGS, valueGS);	
							}
						}			

					}
				}
				if(MapGS!=null && MapGS.size()>0){
					for (Map.Entry<String, Object> entryGS : MapGS.entrySet()) {
						// 将KEY值变为XXGXXS形式
						key = entryGS.getKey().split("_")[0]+"G"+entryGS.getKey().split("_")[1]+"S";
						value = Integer.parseInt(entryGS.getValue().toString());
						//key：此档此速度  value：发生次数
						retMap.put(key, value);
						key = null;
					}
				}
				int ZG1S=MapGetter.getInt(retMap,"0G1S");
				int ZG2S=MapGetter.getInt(retMap,"0G2S");
				int ZG3S=MapGetter.getInt(retMap,"0G3S");
				paramTen.put("0G1S",MapGetter.getString(retMap,"0G1S"));
				retMap.put("total0G3S",String.valueOf(ZG1S+ZG2S+ZG3S));
				retMap.put("total0G1S",String.valueOf(ZG1S));
				retMap.put("totalCnt", totalCnt);
				retMap.put("vehicleID", vehicleID);
				retMap.put("tmnl", tmnl_softedition);
				retMap.put("DDHXNums", DDHXNums);
				if(!StringUtil.isValid(DDHXNums)){
					DDnum = 0;
				} else {
					DDnum = Integer.parseInt(DDHXNums);
				}
				//新版本终端
				if(tmnlof432.contains(tmnl_softedition)||soft502.toLowerCase().contains(tmnl_softedition)){
					if(0 == totalCnt-DDnum){
						
					} else {
						listDataMap.add(retMap);
					}
				} else {
					listDataMap.add(retMap);
				}
			}
			valList.clear();
		}
		return listDataMap;
		
	}
	
	/**
	 * 颜色区域占比计算
	 * 
	 * @param dataSize
	 * @param paraSetList
	 * @return
	 */
	public Map<String, Object> colorJS(int dataSize, List<Map<String, Object>> paraSetList, Map<String,Map<String,Object>> param) {
		Map<String, Object> data = new HashMap<String, Object>();
		String TIMES="0";
		for (int i = 1; i < dataSize; i++) {
			Map<String, Object> paraSet = paraSetList.get(i);
			if(i==dataSize-1){
				TIMES=MapGetter.getString(paraSet, "parasdd2_val10");
			}
			data.put("ZG1S", MapGetter.getString(paraSet, "ZG1S"));
			data.put("ZG3S", MapGetter.getString(paraSet, "ZG3S"));
			data.put("totalCnt", MapGetter.getString(paraSet, "totalCnt"));
			data.put("tmnl", MapGetter.getString(paraSet, "tmnl"));
			data.put("DDHXNums", MapGetter.getString(paraSet, "DDHXNums"));
			int length = colKeyArr.length;
			for (int j = 0; j < length-1; j++) {
				String colorCode = MapGetter.getString(paraSet, colKeyArr[j]);
				String color = StringUtil.isValid(colorCode)&&param.get(colorCode)!=null?MapGetter.getString(param.get(colorCode), "CS_Value"):"";
				double Value = StringUtil.toDouble(MapGetter.getString(paraSet,valKeyArr[j]));
				double colorV = StringUtil.toDouble(MapGetter.getString(data,color));
				if (Value > 0) {
					if (StringUtil.isValid(color)) {
						data.put(color, NumberFormat.add(colorV,Value));
					} else {
						double colorO = StringUtil.toDouble(MapGetter.getString(data, "#"));
						data.put("#", NumberFormat.add(colorO,Value));
					}
				}
			}
			data.put("0G1Stimes", TIMES);
		}
		
		return data;
	}
	
	/**
	 * 时间段DutyCycle源数据
	 **/
	private String getDutyCycleDataOfBetweenTime(String vehicleID,
			String begintime, String endtime,String locLang,String flag) {
		String total5="";
		String tableDate = "";
		String tableDate2 = "";
		
		List<Map<String,Object>> daydefList = drivingBehavior2DAO.getDateOfHaveDutyCycleData(vehicleID, begintime, endtime, false);
		
		if(null != daydefList && daydefList.size()>0){
			tableDate = MapGetter.getString(daydefList.get(0),"workStateTime");
			tableDate2= MapGetter.getString(daydefList.get(1),"workStateTime");
			//判断两条记录是否为同一条,同一条不做处理,且前一天日期必须为档位车速日期前一天，后一天为档位车速数据日期
			if(tableDate.equals(tableDate2)){
				total5 = "";
			}else{	
				
//					长期负荷循环时间--157 图5
				String longTerm_Bgn = drivingBehavior2DAO.getDutyCycleReplyValue(vehicleID,flag,tableDate.replaceAll("-",""), 157);
				if(!StringUtil.isValid(longTerm_Bgn)){
					return "";
				}
				String longTerm_End = drivingBehavior2DAO.getDutyCycleReplyValue(vehicleID,flag,tableDate2.replaceAll("-",""), 157);
				if(!StringUtil.isValid(longTerm_End)){
					return "";
				}
//					长期负荷循环比例图总时间--159 图5
				String total_Bgn = drivingBehavior2DAO.getDutyCycleReplyValue(vehicleID,flag,tableDate.replaceAll("-",""), 159);
				if(!StringUtil.isValid(total_Bgn)){
					return "";
				}
				String total_End = drivingBehavior2DAO.getDutyCycleReplyValue(vehicleID,flag,tableDate2.replaceAll("-",""), 159);
				if(!StringUtil.isValid(total_End)){
					return "";
				}
					DecimalFormat df = new DecimalFormat("0.00"); 	
					double total_int = Double.parseDouble(total_End)-Double.parseDouble(total_Bgn);
					String[] longTs_Bgn = longTerm_Bgn.split(",");
					String[] longTs_End = longTerm_End.split(",");
					if(longTs_Bgn.length==longTs_End.length){
						for (int i = 0; i < longTs_End.length; i++) {
						double longTss_End = Double.parseDouble(longTs_End[i]);
						double longTss_Bgn = Double.parseDouble(longTs_Bgn[i]);
						if(total_int == 0){
							total5 += "%,0";
						}else{
							total5 += "%,"+df.format((longTss_End-longTss_Bgn)/total_int*100);
						}
					
						}
					total5 = total5.substring(2, total5.length());

		    }
		}

	}

		return total5;
	}
	
	/**
	 * 查询手动添加的任务
	 * @return
	 */
	public List<Map<String, Object>> getHandVclInfo(){
		DrivingBehavior2DAO dB2DAO = new DrivingBehavior2DAO();
		List<Map<String, Object>> listData = new ArrayList<Map<String,Object>>();
		listData = dB2DAO.getHandVclInfo();
		return listData;
	}
	
	/**
	 * 根据设备号获取设备ID
	 * @return
	 */
	public Map<String, Object> getVclInfoByNum(String vehicleNumber){
		DrivingBehavior2DAO dB2DAO = new DrivingBehavior2DAO();
		Map<String, Object> mapData = new HashMap<String,Object>();
		mapData = dB2DAO.getVclInfoByNum(vehicleNumber);
		return mapData;
	}
	
	/**
	 * 更新任务状态
	 * @return
	 */
	public boolean updateTaskInfo(String id,int state){
		DrivingBehavior2DAO dB2DAO = new DrivingBehavior2DAO();
		boolean isFh = false;
		isFh =  dB2DAO.updateTaskInfo(id,state);
		return isFh;
	}
	
	public void initExecuParam(){
		DrivingBehavior2DAO dB2DAO = new DrivingBehavior2DAO();
		drivingBehavior2DAO = dB2DAO;
		drivingBehavior2DAO.initparamDao();
	}
	public static void main(String[] args) {
		List<String> sqlList = new ArrayList<String>();
		sqlList.add("111;");
		sqlList.add("111;");
		sqlList.add("111;");
		System.out.print(sqlList.toString());
	}
}

